﻿using System;
using MovieBuddy.Events;
using System.Windows.Controls;
using MovieModel.Model;

namespace MovieBuddy.Views
{
    public interface IMovieBuddyViewController<out T>
    {
        void InvokeSearchChanged(SearchEventArgs e);
        T Control { get; }
        ISearchAcceptor SearchAcceptor { get; }
    }

    public abstract class MovieBuddyViewController<T> : IMovieBuddyViewController<T> where T : UserControl
    {
        public readonly Manager Manager;
        public T Control { get; private set; }
        public abstract ISearchAcceptor SearchAcceptor { get; }

        protected MovieBuddyViewController(Manager manager, T control)
        {
            Manager = manager;
            Control = control;
            SearchChanged += (sender, e) => SearchChangedImpl(e);
        }

        public event EventHandler<SearchEventArgs> SearchChanged;

        public void InvokeSearchChanged(SearchEventArgs e)
        {
            EventHandler<SearchEventArgs> handler = SearchChanged;
            if (handler != null) handler(this, e);
        }

        protected abstract void SearchChangedImpl(SearchEventArgs e);
    }
}
